<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>模板消息</title>
    <link rel="shortcut icon" type="image/ico" href="${basePath}/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="${basePath}/css/style-1.css" />
    <link rel="stylesheet" type="text/css" href="${basePath}/css/style_2_common.css" />
    <link rel="stylesheet" type="text/css" href="${basePath}/css/more_img.css" />
    <script type="text/javascript" src="${basePath}/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="${basePath}/js/jscolor.js"></script>
</head>

<body id="nv_member" class="pg_CURMODULE">
    <#assign current='menu_template'>
    <div id="wp" class="wp">
        <#include "/include/header.html"/>
        <!--中间内容-->
        <div class="contentmanage">
            <div class="developer">
                <div class="tableContent">
                    <#include "/include/left.html"/>
                    <#include "/include/wxtop.html"/>
                    <div class="content">
                        <div class="cLineB">
                            <h4 class="left">模板消息配置</h4>
                            <div class="clr"></div>
                        </div>
                        <div style="background: #fefbe4; border: 1px solid #f3ecb9; color: #993300; padding: 10px; margin-bottom: 5px; font-size: 12px; margin-top: 5px;">
                            温馨提示：此功能仅限于已开通微信支付功能的公众号使用。
                            <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 此处可以自定义模版消息的<span style="color: #029700">头部颜色</span>和<span style="color: #029700">内容颜色</span>。
                        </div>
                        <table width="100%" cellspacing="0" cellpadding="0" border="0" class="ListProduct">
                            <thead>
                                <tr align="center">
                                    <th>模板编号</th>
                                    <th>模板名</th>
                                    <th>回复内容</th>
                                    <th>所属行业</th>
                                    <th>头部颜色</th>
                                    <th>文字颜色</th>
                                    <#--<th>状态</th>-->
                                    <th class="norightborder">模板ID</th>
                                </tr>
                            </thead>
                            <tbody id="templateItems">
                                
                            </tbody>
                        </table>
                        <div style="margin: 20px auto; width: 50px; height: 50px;">
                        	<button class="btnGreen"  onclick="saveTemplate()">保存</button>
                        </div>
                    </div>
                    <div class="clr"></div>
                </div>
            </div>
        </div>
        <!--底部-->
    </div>
    <#include "/include/footer.html"/>
</body>
<script type="text/javascript">
$(function() {
	getTemplate();
});
function getTemplate(){
	$.ajax({
        async: false,
        type: "POST",
        url: "${basePath}/admin/mass/gettemplate",
        dataType: "json",
        success: function(json) {
            if(json.length > 0){
            	addTemplate(json);
            }else{
            	alert("信息获取失败");
            }
        }
    });
}
function addTemplate(json){
	for(i=0;i<json.length;i++){
		var data = json[i];
		var tdom ="<tr>";
		tdom+="<td><input type='hidden' value='"+data.id+"' class='templateid' />"+data.templateno+"</td>";
		tdom+="<td>"+data.templatename+"</td>";
		tdom+="<td><pre>"+data.pushContent+"</pre></td>";
		tdom+="<td><pre>"+data.industry+"</pre></td>";
		tdom+="<td><input type='text' style='width: 55px; background: rgb(2, 151, 0) none repeat scroll 0% 0%; color: rgb(255, 255, 255);' class='px color head_color' value='"+data.headColor+"'></td>";
		tdom+="<td><input type='text' style='width: 55px; background: rgb(0, 0, 0) none repeat scroll 0% 0%; color: rgb(255, 255, 255);' class='px color content_color' value='"+data.contentColor+"'></td>";
		/*
		tdom+="<td><select name='state' class='state'>";
		if(data.state==1){
			tdom+="<option value='2'>关闭</option><option selected value='1'>开启</option>";
		}else{
			tdom+="<option selected value='2'>关闭</option><option value='1'>开启</option>";
		}
		tdom+="</select></td>";
		*/
		tdom+="<td class='norightborder'>"+data.templateid+"</td>";
		tdom+="</tr>";
		$('#templateItems').append(tdom);
	}
}

function saveTemplate(){
	//获取数据
	var templates = new Array()
	var tindex = 0;
	$('#templateItems').find('tr').each(function(){
		var tid = $(this).find(".templateid").val();
		var headcolor = $(this).find('.head_color').val();
		var contentcolor = $(this).find('.content_color').val();
		/*
		var state = $(this).find('.state').val();
		templates[tindex] = {"id":tid,"headColor":headcolor,"contentColor":contentcolor,"state":state}
		*/
		templates[tindex] = {"id":tid,"headColor":headcolor,"contentColor":contentcolor}
		tindex++;
	});
	//提交数据
	$.ajax({
        async: false,
        type: "POST",
        url: "${basePath}/admin/mass/saveTemplate",
        data: {"templates":JSON.stringify(templates)},
        success: function(json) {
            if ($.trim(json.errormsg) != "") {
                msg = json.errormsg + "\n";
            }else{
            	alert("保存成功");
            }
        }
    });
}

</script>

</html>
